package cn.stronglink.assetmanage.business.inspection.model;

import java.io.IOException;
import java.util.List;

import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.business.inspection.presenter.RepairRegisterPresenter;
import cn.stronglink.assetmanage.dao.AssetDao;
import cn.stronglink.assetmanage.dao.DaoManager;
import cn.stronglink.assetmanage.dao.RepailDetailDao;
import cn.stronglink.assetmanage.dao.RepairDao;
import cn.stronglink.assetmanage.dao.UserDao;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.entity.Repair;
import cn.stronglink.assetmanage.entity.Task;
import cn.stronglink.assetmanage.entity.User;
import cn.stronglink.assetmanage.utils.Constants;
import cn.stronglink.netrequest.business.repail.RepairService;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 维修登记数据库操作
 * Created by zhengjinglan on 2018/6/18.
 */

public class RepairRegisterModel {

    /**
     * 保存巡检详情表到服务器
     * @param repailDetail
     */
    public void savePatrolDetail(RepailDetail repailDetail){

    }

    private Repair getRepairByOrderId(String orderId){
        Repair repair = DaoManager
                .getDaoSession(MyApplication.APP_CONTEXT).getRepairDao().queryBuilder()
                .where(RepairDao.Properties.Id_.eq(orderId)).list().get(0);
        DaoManager.getDaoSession(MyApplication.APP_CONTEXT).clear();
        if (repair != null){
            return repair;
        }
        return null;
    }

    /**
     * 通过sn查询是否存在Asset
     * @param sn
     * @return
     */
    public Asset searchAssesBySn(String sn){
        List<Asset> asset = DaoManager.getDaoSession(MyApplication.APP_CONTEXT).getAssetDao().queryBuilder().where(AssetDao.Properties.SerialNo.eq(sn))
                .list();
        if (asset !=null && asset.size()>0){
            return asset.get(asset.size()-1);
        }
        return null;
    }
}
